<?php
	header("Content-type: text/html;charset=utf8");
	require_once("../db/dbclass.php");
	require_once("../model/userinfo.php");
	require_once("../utils/config.php");
	require_once("../utils/common.php");
	$myDb=&DbController::getInstance();
	$user_id=$_POST['user_id'];
	$param="select * from yj_primsg where primsg_status=1 and (receiver_id='".$user_id."' or sender_id in ".ROOT.")";
	$result=$myDb->exec_query($param);
	$result_i="failure";
	if($result==TRUE){
		$result_row= mysqli_num_rows($result);
		$num=$result_row;
		$arr_messege="";
		if($result_row==0){
			$result_i="success";
		}else{
			$result_i="success";
			$arr_messege=array($num);
			$i=0;
			while($row = mysqli_fetch_array($result,MYSQL_ASSOC)){
				$arr_messege[$i++]=$row['sender_id'];
				$param="UPDATE yj_primsg SET primsg_status=0 where primsg_id = '".$row['primsg_id']."'";
				$result_update=$myDb->exec_query($param);
				if($result_update==TRUE){
					
				}else{
					$result_i="failure";
					$arr=array(
						"result"=>$result_i,
						"message"=>""
					);
					echo json_encode($arr);
					while($row = mysqli_fetch_array($result,MYSQL_ASSOC)){
						$param="UPDATE yj_primsg SET primsg_status=1 where primsg_id = '".$row['primsg_id']."'";
						$result_update=$myDb->exec_query($param);
					}
					return;
				}
			}
		
		}
		$arr=array(
			"result"=>$result_i,
			"message"=>$arr_messege
		);
		echo json_encode($arr);
		return;
	}
	$arr=array(
		"result"=>$result_i,
		"message"=>""
	);
	echo json_encode($arr);
?>